package com.home.auto_navigation.ui.pages;

import java.util.HashMap;
import java.util.Map;

import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import com.home.auto_navigation.common.AutoNavigationFileDecorator;
import com.home.auto_navigation.common.api.NavigationLink;
import com.home.auto_navigation.ui.AbstractPageObject;
import com.home.auto_navigation.ui.controllers.Button;

public class HomePage extends AbstractPageObject {

	// @FindBy(xpath =
	// "//div[@class='main_menu']/a[@class='active'][text()='посты']")
	// private WebElement posts;
	// @FindBy(xpath = "//table[@class='menu']//td[@class='item all active']/a")
	// private WebElement postAll;
	// @FindBy(linkText = "q&a")
	// private WebElement qa;
	// @FindBy(linkText = "хабы")
	// private WebElement hubs;
	// @FindBy(xpath = "//a")
	// private WebElement hantim;
	@FindBy(id = "hp01v0")
	private WebElement uniqueElement;
	@NavigationLink(successor = DownloadsPage.class)
	@FindBy(xpath = "//a/h3[text()='Downloads']")
	private Button downloads;
	@NavigationLink(successor = LoginPage.class)
	@FindBy(linkText = "Sign In/Register")
	private Button loginPage;

	public HomePage() {
		PageFactory.initElements(new AutoNavigationFileDecorator(getDriver()),
				this);
		this.successors = new HashMap<Class<? extends AbstractPageObject>, Button>();
		this.successors.put(DownloadsPage.class, downloads);
		this.successors.put(LoginPage.class, loginPage);
	}

	public void clickD() {
		downloads.click();
	}

	@Override
	public boolean isExist() {
		try {
			if (uniqueElement.isDisplayed() && loginPage.isPresent()) {
				return true;
			} else
				return false;
		} catch (NoSuchElementException e) {
			return false;
		}
		// try {
		// if (posts.isDisplayed() && postAll.isDisplayed()) {
		// return true;
		// } else
		// return false;
		// } catch (NoSuchElementException e) {
		// return false;
		// }
	}

	@Override
	public void invokeSuccessor(Map<String, String> businessData,
			Class<? extends AbstractPageObject> page) {
		if (businessData != null) {
			if (page.equals(LoginPage.class)) {

			}
		}
	}
}
